package com.icedevcloud.upms.controller.admin.dict;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.icedevcloud.common.core.api.R;
import com.icedevcloud.common.core.log.IceLog;
import com.icedevcloud.common.core.page.PageResult;
import com.icedevcloud.upms.controller.admin.dict.dto.AddDictReqDto;
import com.icedevcloud.upms.controller.admin.dict.dto.DictPageReqDto;
import com.icedevcloud.upms.controller.admin.dict.dto.UpdateDictReqDto;
import com.icedevcloud.upms.entity.SysDict;
import com.icedevcloud.upms.service.ISysDictService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 字典表 前端控制器
 * </p>
 *
 * @author XiaoBingBy
 * @since 2023-08-13
 */
@Tag(name = "字典接口类")
@RequiredArgsConstructor
@RestController
@RequestMapping("/sysDict")
public class SysDictController {

    private final ISysDictService iSysDictService;

    @IceLog
    @SaCheckPermission("upms:dict:page")
    @Operation(summary = "字典列表接口")
    @RequestMapping("/dictPage")
    public R<PageResult<SysDict>> dictPage(@RequestBody @Validated DictPageReqDto reqDto) {
        PageResult<SysDict> result = iSysDictService.dictPage(reqDto);
        return R.ok(result);
    }

    @IceLog
    @SaCheckPermission("upms:dict:add")
    @Operation(summary = "添加字典接口")
    @RequestMapping("/add")
    public R<Boolean> add(@RequestBody @Validated AddDictReqDto reqDto) {
        Boolean result = iSysDictService.add(reqDto);
        return R.ok(result);
    }

    @IceLog
    @SaCheckPermission("upms:dict:update")
    @Operation(summary = "更新字典接口")
    @RequestMapping("/update")
    public R<Boolean> update(@RequestBody @Validated UpdateDictReqDto reqDto) {
        Boolean result = iSysDictService.update(reqDto);
        return R.ok(result);
    }

    @IceLog
    @SaCheckPermission("upms:dict:delete")
    @Operation(summary = "删除字典接口")
    @DeleteMapping("/delete")
    public R<Boolean> delete(@NotNull(message = "ID不能为空") Long id) {
        Boolean result = iSysDictService.delete(id);
        return R.ok(result);
    }

}
